package com.rwind.dynamic.app;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@EnableWebMvc
@SpringBootApplication(
        scanBasePackages = {"com.rwind.dynamic.controller", "com.rwind.dynamic.service"},
        exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, JmxAutoConfiguration.class})
public class App {

    /**
     * 防止增加@EnableWebMvc注解后，返回xml数据格式
     * @return
     */
    @Bean
    public WebMvcConfigurer customConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
                configurer.defaultContentType(MediaType.APPLICATION_JSON);
            }
        };
    }

    public static void main(String[] args) {
        //SpringApplication.run(App.class, args);
        //方式一

        new SpringApplicationBuilder(App.class)
                //.parent(ParentConfig.class).web(WebApplicationType.NONE)
                // .child(WebConfig.class).web(WebApplicationType.SERVLET)
                // .sibling(RestConfig.class).web(WebApplicationType.SERVLET)
                .run(args);

        /*
        ConfigurableApplicationContext context = new SpringApplicationBuilder(App.class)
                .properties("spring.config.location=classpath:/test-profiles.yml")
                .properties("spring.profiles.active=oracle")
                .run(args);
        // 输出变量
        //System.out.println(context.getEnvironment().getProperty("jdbc.driver"));

        // 启动第二个Spring容器，指定端口为8848
        ConfigurableApplicationContext context2 = new SpringApplicationBuilder(App.class)
                .properties("spring.config.location=classpath:/test-profiles.yml")
                .properties("spring.profiles.active=mysql")
                .properties("server.port=8848")
                .run(args);
        */


    }
}